﻿using System;
using System.Net;
using System.Windows;
using System.Collections.ObjectModel;

namespace Transportr
{
    public class MapModel : Model
    {
        public MapViewModel ViewModel { get; private set; }
        public ObservableCollection<MapMarkerViewModel> Markers { get; private set; }
        public bool IsDataLoaded { get; private set; }
        public event UpdatedHandler Updated;

        public MapModel()
        {
            ViewModel = new MapViewModel();
            Markers = new ObservableCollection<MapMarkerViewModel>();
            Markers.Add(new MapMarkerViewModel() { Latitude = 47.47, Longitude = 19.07 });
            LocationModel.LocationChanged += new LocationChangedHandler(LocationModel_LocationChanged);
            IsDataLoaded = true;
        }

        void LocationModel_LocationChanged()
        {
            ViewModel.Center = new System.Device.Location.GeoCoordinate(LocationModel.CurrentLocation.Latitude, LocationModel.CurrentLocation.Longitude);
            ViewModel.ZoomLevel = 10;
            if (Updated != null)
                Updated("");
        }

        public void AddMarker(double lat, double lon)
        {
            if (Markers != null)
                Markers.Add(new MapMarkerViewModel() { Latitude = lat, Longitude = lon });
            if (Updated != null)
                Updated("");
        }
    }
}
